{include file="common:header" /}
{include file="common:side" /}
    <div id="page-wrapper">
      <!-- 舆情日报 -->
      <!--*************************** content部分开始 ******************-->
      <div class="container-fluid" id="m_main">
        <div class="row m-t-20">
          <div class="col-sm-12">
            <div class="white-box">
              <h2 class="box-title m-b-20">门店基本信息管理</h2>
              <div class="col-sm-8">
                <div class="row">
                  <div class="col-sm-8">
                    <div class="form-group">
                      <label class="control-label">门店名称：</label>
                      <input type="text" class="form-control" placeholder="" v-model="store.name">
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-4">
                    <div class="form-group">
                      <label class="control-label">门店联系人：</label>
                      <input type="text" class="form-control" placeholder="" v-model="store.contacts">
                    </div>
                  </div>
                  <div class="col-sm-4">
                    <div class="form-group">
                      <label class="control-label">联系方式：</label>
                      <input type="text" class="form-control" placeholder="" v-model="store.phone">
                      <span class="help-block"><small>*此联系方式也作为预约电话使用</small></span>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-8">
                    <div class="form-group">
                      <label class="control-label">门店地址：</label>
                      <input type="text" class="form-control" placeholder="" v-model="store.address">
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-8">
                    <div class="form-group">
                      <label class="control-label">门店介绍：</label>
                      <textarea class="form-control" placeholder="请输入..." v-model="store.description">{{store.description}}</textarea>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-12">
                    <div class="form-group m-addsku-pics">
                      <label class="control-label">学院图片：<span><small>(最多上传3张图片，750px*350px)</small></span></label>
                      <div>
                        <label for="add_school_info_pic" class="btn btn-primary waves-effect waves-light" style="line-height: 20px;padding: 6px 10px">添加图片</label>
                        <input type="file" id="add_school_info_pic" name="file" class="addpics" data-amount="1"/>
                        <div class="col-md-12">
                          <div id="school_info_pic_box" class="pic-box"></div>
                          <input type="hidden" name="school_info_pic" class="add-pic" id="school_info_pic" value="" data-id="">
                          <input type="hidden" name="delete_school_info_pic" class="delete-pic" id="delete_school_info_pic">
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-8">
                    <div class="form-group m-addsku-pics">
                      <label class="control-label">门店视频：<span><small>(最多添加3个视频，仅支持腾讯视频链接)</small></span></label>
                      <div class="row">
                        <div class="col-sm-2">
                          <label for="add_vpic1_info_pic" class="btn btn-primary waves-effect waves-light" style="line-height: 20px;padding: 6px 10px">添加图片</label>
                          <input type="file" id="add_vpic1_info_pic" name="file" class="addpics" data-amount="1"/>
                          <div class="col-md-12">
                            <div id="vpic1_info_pic_box" class="pic-box"></div>
                            <input type="hidden" name="vpic1_info_pic" class="add-pic" id="vpic1_info_pic" value="" data-id="">
                            <input type="hidden" name="delete_vpic1_info_pic" class="delete-pic" id="delete_vpic1_info_pic">
                          </div>
                        </div>
                        <div class="col-sm-10">
                          <input type="text" class="form-control" placeholder="" v-model="store.video1">
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-sm-2">
                          <label for="add_vpic2_info_pic" class="btn btn-primary waves-effect waves-light" style="line-height: 20px;padding: 6px 10px">添加图片</label>
                          <input type="file" id="add_vpic2_info_pic" name="file" class="addpics" data-amount="1"/>
                          <div class="col-md-12">
                            <div id="vpic2_info_pic_box" class="pic-box"></div>
                            <input type="hidden" name="vpic2_info_pic" class="add-pic" id="vpic2_info_pic" value="" data-id="">
                            <input type="hidden" name="delete_vpic2_info_pic" class="delete-pic" id="delete_vpic2_info_pic">
                          </div>
                        </div>
                        <div class="col-sm-10">
                          <input type="text" class="form-control" placeholder="" v-model="store.video2">
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-sm-2">
                          <label for="add_vpic3_info_pic" class="btn btn-primary waves-effect waves-light" style="line-height: 20px;padding: 6px 10px">添加图片</label>
                          <input type="file" id="add_vpic3_info_pic" name="file" class="addpics" data-amount="1"/>
                          <div class="col-md-12">
                            <div id="vpic3_info_pic_box" class="pic-box"></div>
                            <input type="hidden" name="vpic3_info_pic" class="add-pic" id="vpic3_info_pic" value="" data-id="">
                            <input type="hidden" name="delete_vpic3_info_pic" class="delete-pic" id="delete_vpic3_info_pic">
                          </div>
                        </div>
                        <div class="col-sm-10">
                          <input type="text" class="form-control" placeholder="" v-model="store.video3">
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-12">
                    <div class="form-group m-addsku-pics">
                      <label class="control-label">学员风采：<span></span></label>
                      <!-- 加载编辑器的容器 -->
  	                  <script id="contents-box" name="content" type="text/plain"></script>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-sm-4 ta-c">
                <div class="m-img m-b-30"><img :src="store.wxcode" alt="" style="width:200px;height:200px"></div>
                <a :href="store.wxcode" download="wxcode.png">点击下载</a>
              </div>
              <div class="row m-t-40">
                <div class="col-sm-8 ta-c">
                  <button type="button" name="" class="btn btn-outline btn-primary m-r-40" @click="doSubmit()">提交</button>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- /.row -->
      </div>
      <!--*************************** content部分结束 ******************-->

      <!-- <footer class="footer text-center"> 2017 &copy; Ample Admin brought to you by themedesigner.in </footer> -->
    </div>
  {include file="common:js" /}
  {include file="common:footer" /}
  <script type="text/javascript" src="/web/uedit/ueditor.config.js"></script>
  <script type="text/javascript" src="/web/uedit/ueditor.all.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/jquery.fileupload.js"></script>
  <script src="/web/js/edit.js"></script>
  <script>
  	$(function() {
  		upload_photo('#add_school_info_pic','/dboard/upload/cover_upload');
      upload_photo('#add_vpic1_info_pic','/dboard/upload/cover_upload');
      upload_photo('#add_vpic2_info_pic','/dboard/upload/cover_upload');
      upload_photo('#add_vpic3_info_pic','/dboard/upload/cover_upload');
  	});
  </script>

  <script type="text/javascript">
    var vm = new Vue({
      el: '#m_main',
      data() {
        return {
          sid: '{$sid}',
          store: {}
        }
      },
      mounted() {
        // 初始化富文本编辑器
        var ue = UE.getEditor('contents-box');
        if(this.sid) {this.requestData()}
      },
      methods: {
        requestData() {
          let that = this;
          axios.post('/dboard/shop/infoData', {sid: that.sid},{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              that.store = res.data.Data.store;
              var schoolStr = "";
              var idStr = "";
              if(res.data.Data.store.pic1&&res.data.Data.store.pic2&&res.data.Data.store.pic3) {
                schoolStr = res.data.Data.store.pic1+','+res.data.Data.store.pic2+','+res.data.Data.store.pic3+",";
                idStr = "1,2,3";
              } else if(res.data.Data.store.pic1&&res.data.Data.store.pic2&&!res.data.Data.store.pic3) {
                schoolStr = res.data.Data.store.pic1+','+res.data.Data.store.pic2+",";
                idStr = "1,2";
              } else if(res.data.Data.store.pic1&&!res.data.Data.store.pic2) {
                schoolStr = res.data.Data.store.pic1+",";
                idStr = "1";
              }

              $("#school_info_pic").val(schoolStr);
              $("#school_info_pic").attr('data-id', idStr);

              if($("#school_info_pic").val().length != 0){
                show_photo('#school_info_pic');
              }
              $("#vpic1_info_pic").val(res.data.Data.store.vpic1);
              if($("#vpic1_info_pic").val().length != 0){
                show_photo('#vpic1_info_pic');
              }
              $("#vpic2_info_pic").val(res.data.Data.store.vpic2);
              if($("#vpic2_info_pic").val().length != 0){
                show_photo('#vpic2_info_pic');
              }
              $("#vpic3_info_pic").val(res.data.Data.store.vpic3);
              if($("#vpic3_info_pic").val().length != 0){
                show_photo('#vpic3_info_pic');
              }

              $("#contents-box").val(res.data.Data.store.store_photos);
              // 初始化富文本编辑器
              var ue = UE.getEditor('contents-box');
              var str = $("#contents-box").val();
              ue.ready(function() {
                ue.setContent(str,false);
              });

            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        },
        // 提交
        doSubmit(){
          var that = this;
          var param = {
            sid: that.sid,
            name: that.store.name,
            contacts: that.store.contacts,
            phone: that.store.phone,
            address: that.store.address,
            description: that.store.description,
            video1: that.store.video1,
            video2: that.store.video2,
            video3: that.store.video3,
            store_photos: UE.getEditor('contents-box').getContent(),
          }
          var schoolStr = $('#school_info_pic').val();
          var schoolArray = schoolStr.split(",");
          schoolArray.splice(schoolArray.length-1, 1);
          if(schoolArray.length>0) { param.pic1 = schoolArray[0] }
          if(schoolArray.length>1) { param.pic2 = schoolArray[1] }
          if(schoolArray.length>2) { param.pic3 = schoolArray[2] }
          if(schoolArray.length>3) { alert('学院图片最多上传3张');return false}

          var vpic1Str = $('#vpic1_info_pic').val();
          var vpic1Array = vpic1Str.split(",");
          vpic1Array.splice(vpic1Array.length-1, 1);
          if(vpic1Array.length>0) { param.vpic1 = vpic1Array[0] };
          if(vpic1Array.length>1) { alert('视频封面最多上传1张');return false}

          var vpic2Str = $('#vpic2_info_pic').val();
          var vpic2Array = vpic2Str.split(",");
          vpic2Array.splice(vpic2Array.length-1, 1);
          if(vpic2Array.length>0) { param.vpic2 = vpic2Array[0] };
          if(vpic2Array.length>1) { alert('视频封面最多上传1张');return false}

          var vpic3Str = $('#vpic1_info_pic').val();
          var vpic3Array = vpic3Str.split(",");
          vpic3Array.splice(vpic3Array.length-1, 1);
          if(vpic3Array.length>0) { param.vpic3 = vpic3Array[0] };
          if(vpic3Array.length>1) { alert('视频封面最多上传1张');return false}

          axios.post('/dboard/shop/editShopinfo', param,{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              alert(res.data.Msg)
              window.location.reload();
            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        }
      }
    })
  </script>
